﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UI.Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            //MyTableTest();
            // AddControl();
        }

        private void AddControl()
        {
            int rowcol = 8;
            int rows = 3;

            //计算宽高
            int WidthHeight = (int)(tableLayoutPanel1.Width / rowcol);
            int height = (int)(tableLayoutPanel1.Height / rows);
            //重新设置表格
            //tableLayoutPanel1为TableLayoutPanel控件
            tableLayoutPanel1.Controls.Clear();
            tableLayoutPanel1.RowCount = rows;
            tableLayoutPanel1.ColumnCount = rowcol;
            tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
            tableLayoutPanel1.Refresh();
            for (int i = 0; i < tableLayoutPanel1.ColumnStyles.Count; i++)
            {
                tableLayoutPanel1.ColumnStyles[i].SizeType = SizeType.Absolute;
                tableLayoutPanel1.ColumnStyles[i].Width = WidthHeight;
            }

            for (int i = 0; i < tableLayoutPanel1.RowStyles.Count; i++)
            {
                tableLayoutPanel1.RowStyles[i].SizeType = SizeType.Absolute;
                tableLayoutPanel1.RowStyles[i].Height = height;
            }


            Label lb = null;
            TextBox txt = null;

            for (int i = 0; i < 10 * 2; i++)
            {
                if (i % 2 == 0)
                {
                    lb = new Label();
                    lb.Name = "lb" + i;
                    lb.Text = "标题" + i + "：";
                    lb.Dock = DockStyle.Top;
                    lb.TextAlign = ContentAlignment.MiddleRight;
                    lb.Padding = lb.Margin = new Padding(0);
                    this.tableLayoutPanel1.Controls.Add(lb);
                    if (i == 10) lb.Visible = false;
                }
                else
                {
                    txt = new TextBox();
                    txt.Name = "lb" + i;
                    txt.Dock = DockStyle.Fill;

                    this.tableLayoutPanel1.Controls.Add(txt);
                    //this.tableLayoutPanel1.SetColumnSpan(txt, 3);
                    if (i == 11) txt.Visible = false;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form4 frm = new Form4();
            frm.Show();
        }

        //Table测试
        private void MyTableTest()
        {
            //DataTable dt = 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form3 frm = new Form3();
            frm.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2();
            frm.Show();
        }
    }
}
